<?php

namespace App\Listener;
use App\Event\SmsSend;
use App\Exception\BusinessException;
use App\Utils\SmsUtil;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;

#[Listener]
class SmsSendListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            SmsSend::class,
        ];
    }

    public function process(object $event):void
    {
        if(!$event instanceof SmsSend){
            return ;
        }
        if(false === SmsUtil::send($event->smsRecord->code)){
            throw new BusinessException("短信发送失败");
        }
    }
}